import logging
import os
import logging.handlers

# 项目执行路径
import time

BaseDir = os.path.dirname(os.path.abspath(__file__))


# class NoParsingFilter(logging.Filter):
#     def filter(self, record):
#         if record.name == "airtest.core.android.adb" or "airtest.core.api":
#             return False
#         return True


def init_log():
    # 格式器
    fmt = '%(asctime)s %(levelname)s [%(name)s] [%(filename)s(%(funcName)s:%(lineno)d)] - %(message)s'
    formatt = logging.Formatter(fmt=fmt)
    # 处理器
    log_file = BaseDir + f'/log/{time.strftime("%Y%m%d%H%M%S")}.log'
    handler = logging.handlers.TimedRotatingFileHandler(log_file, when='midnight', interval=1, backupCount=7,
                                                        encoding="utf-8")
    handler.setLevel(logging.INFO)
    handler.setFormatter(formatt)
    # 日志器
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    logger.addHandler(handler)
    # logger.addFilter(NoParsingFilter())
